package org.limit.bookServe.vo;

import org.limit.bookServe.bean.Book;
import org.limit.bookServe.service.BookService;
import org.limit.bookServe.service.impl.BookServiceImpl;

import java.util.InputMismatchException;
import java.util.List;
import java.util.Objects;

import static org.limit.bookServe.utils.BaseClass.*;
import static org.limit.bookServe.utils.SystemConstants.SHOW_BOOKS_INFO_LIST;

/**
 * @author 1.
 * @version 1.0
 * @description:
 * @date 2023/11/6 0:11
 */
public class BookVO {
    private final BookService bookService;

    public BookVO(List<Book> bookList) {
        this.bookService = new BookServiceImpl(bookList);
    }

    //添加书籍
    public void addBookOne() {
        println("请输入书名: ");
        String bookName = input.nextLine();
        println("请输入存入数量: ");
        int bookNum = input.nextInt();
        if (!Objects.equals(bookName, "") && (bookNum > 0 && bookNum < 999)) {
            Book newBook = new Book(bookName, bookNum);
            bookService.insertBook(newBook);
        } else {
            println("输入有误，书籍未上架！");
        }
    }

    //查找书籍
    public void findBookOne() {
        println("请输入您要查找的书名: ");
        String bookName = input.nextLine();
        bookService.findBookOne(bookName);
    }

    //删除书籍
    public void deletedBookOne() {
        println("请输入你要删除的书籍代码: ");
        try {
            int demo = input.nextInt();
            bookService.deletedBookOne(demo);
        } catch (InputMismatchException e) {
            println("请输入正确的书籍代码！");
        }
    }

    //显示书籍
    public void showAllBooks() {
        println(resourceReader(SHOW_BOOKS_INFO_LIST));
        bookService.showAllBooks();
        //换行
        println();
    }

    //借阅书籍
    public void borrowBookOne() {
        println("请输入您要借阅的书籍名:");
        String bookName = input.nextLine();
        if (!Objects.equals(bookName, "")) {
            bookService.borrowBookOne(bookName);
        } else {
            println("书名不规范！");
        }
    }

    //归还书籍
    public void returningBook() {
        println("请输入你要归还的书籍名:");
        String bookName = input.nextLine();
        if (!Objects.equals(bookName, "")) {
            bookService.returningBook(bookName);
        } else {
            println("书名不规范！");
        }
    }

}















